<template>
    <view>
	<!-- 
        <view class="headimg">
            <view class="img" @tap="chooseImg">
                <image class="head" :src="imageUrl"></image>
            </view>
			<view>上传头像</view>
        </view> -->

        <view class="name">
			<view style="width: 30%;">
				<text style="color: red">*</text>
				<text>讲师名称：</text>
			</view>
			<view style="width: 60%;">
				  <input placeholder="7字以内" :value="name" @input="inputChangeName" />
			</view>
        </view>

        <view style="margin-top: 10rpx;width: 100%;height: 0.3rpx;background-color: rgba(5, 5, 5, 0.2);"></view>

        <view class="phone">
			<view style="width: 30%;">
				<text style="color: red">*</text>
				<text>手机号码：</text>
			</view>
			<view style="width: 60%;">
				<input type="number" maxlength="11" :value="phone" @input="inputChangePhone" />
			</view>
        </view>
		
        <view style="margin-top: 10rpx;width: 100%;height: 0.3rpx;background-color: rgba(5, 5, 5, 0.2);"></view>

        <view class="notes">
            <text style="color: red">*</text>
            <text>讲师介绍：</text>
        </view>
        <view class="neirong">
            <textarea class="mytest" :value="mytest" @input="inputChangeMytest"></textarea>
        </view>

        <view class="but" v-if="submitstatus == 0">
            <button @tap="onclick" style="background-color: #2ab0fd;width: 620rpx;">提交审核</button>
        </view>
        <view class="but" v-if="submitstatus == 1">
           <button style="background-color: #e8e1dd;width: 620rpx;">审核中...</button>
        </view>
    </view>
</template>

<script>
const app = getApp();
var urlPrefix = app.globalData.urlPrefix;
export default {
    data() {
        return {
            name: null,
            phone: null,
            mytest: null,
            submitstatus: 0,
            imageUrl: null,
			token:null
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        var userId = uni.getStorageSync('userId');
        let that = this;
		 var token = uni.getStorageSync('token')
		 this.token = token
        //判断申请状态
        uni.request({
            url: urlPrefix + '/api/app/applying/judgingApplyForStatus?userId=' + userId,
            method: 'GET',
            header: {
                'content-type': 'application/json',
                "token": this.token
            },
            success: function (res) {
                let data = res.data;
                let info = data.datas;
                if (info != null) {
                    that.setData({
                        phone: info.mobile,
                        name: info.name,
                        mytest: info.introduce,
                        // imageUrl: info.headImgUrl,
                    });
                    if (info.state == 0) {
                        that.setData({
                            submitstatus: 1
                        });
                    }
                }
            }
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
		setTimeout(()=>{
			uni.stopPullDownRefresh();  //停止刷新
			uni.showToast({
			    title: '刷新成功',
				icon: 'none',
			    duration: 2000
			});
		               let that = this;
					   uni.request({
					       url: urlPrefix + '/api/app/applying/judgingApplyForStatus?userId=' + userId,
					       method: 'GET',
					       header: {
					           'content-type': 'application/json',
					           "token": this.token
					       },
					       success: function (res) {
					           let data = res.data;
					           let info = data.datas;
					           if (info != null) {
					               that.setData({
					                   phone: info.mobile,
					                   name: info.name,
					                   mytest: info.introduce,
					               });
					               if (info.state == 0) {
					                   that.setData({
					                       submitstatus: 1
					                   });
					               }
					           }else{
								   that.setData({
								       phone: null,
								       name: null,
								       mytest: null,
								   });
							   }
					       }
					   });
		              
		           },1000)
	},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    onShareTimeline(res) {
        // 分享到朋友圈
        return {};
    },
    methods: {
        onclick: function (params) {
            let that = this;
            // var imageUrl = this.imageUrl;
            // if (this.imageUrl == null) {
            //     uni.showToast({
            //         title: '请点击上传头像',
            //         icon: 'none',
            //         duration: 2000
            //     });
            //     return;
            // }
            if (this.name == null) {
                uni.showToast({
                    title: '请输入讲师名称',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            if (this.name.length > 7) {
                uni.showToast({
                    title: '讲师名称7字以内',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            if (this.phone == null) {
                uni.showToast({
                    title: '请输入手机号码',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            if (!/^1[3456789]\d{9}$/.test(this.phone)) {
                uni.showToast({
                    title: '请输入正确的手机号',
                    icon: 'none'
                });
                return;
            }
            if (this.mytest == null) {
                uni.showToast({
                    title: '请填写讲师介绍',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
			 that.submitforreview();
        },

        submitforreview: function (res) {
            let that = this;
            var userId = uni.getStorageSync('userId');
            uni.request({
                url: urlPrefix + '/api/app/applying/tToExamineLecturer',
                method: 'POST',
                data: {
                    userId: userId,
                    mobile: this.phone,
                    introduce: this.mytest,
                    name: this.name
                },
                header: {
                    'content-type': 'application/json',
                    "token": this.token
                },
                success: function (res) {
					if(res.data.resp_code == 0){
						that.setData({
						    submitstatus: 1
						});
						uni.showToast({
						    title: '提交成功',
						    icon: 'success',
						    duration: 2000
						});
					}else{
						uni.showToast({
						    title: res.data.resp_msg,
						    icon: 'none',
						    duration: 2000
						});
					}
               
                }
            });
        },

        bindRegionChange: function (e) {
            this.setData({
                region: e.detail.value
            });
        },

        inputChangeName(e) {
            let that = this;
            that.setData({
                name: e.detail.value
            });
        },

        inputChangePhone(e) {
            let that = this;
            that.setData({
                phone: e.detail.value
            });
        },

        inputChangeMytest(e) {
            let that = this;
            that.setData({
                mytest: e.detail.value
            });
        },

        chooseImg: function () {
            var that = this;
            uni.chooseImage({
                sizeType: ['original', 'compressed'],
                // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'],
                // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                    var tempFilePaths = res.tempFilePaths;
                    if (res.tempFiles[0].size > 3291456) {
                        uni.showToast({
                            title: '文件不能超过3M',
                            mask: true,
                            duration: 1000
                        });
                        return;
                    }
                    // that.setData({
                    //   imageUrl: tempFilePaths[0],
                    // });
                    // uni.navigateTo({
                    //     url: '/pages/imgcorp/imgcorp?img=' + tempFilePaths[0]
                    // });
                }
            });
        },

        // uploadImage(path) {
        //     var that = this;
        //     that.setData({
        //         imageUrl: path
        //     });
        // }
    }
};
</script>
<style lang="scss">
@import './lecturervideo.scss';
</style>
